// 用户管理接口
import request from '@/utils/request'
import type { SetRoleData, AllRoleResponseData, AddOrUpdateResponse,User,UserResponseData } from './type'
enum API {
  // 获取已有用户信息
  ALLUSER_URL = '/admin/acl/user/',
  // 添加用户
  ADDUSER_URL = '/admin/acl/user/save',
  // 修改用户
  UPDATEUSER_URL = '/admin/acl/user/update',
  // 删除某个账号
  DELETEUSER_URL = '/admin/acl/user/remove/',
  // 批量删除
  DELETEALLUSER_URL = '/admin/acl/user/batchRemove',
  // 获取用户职位,全部职位
  ALLROLE_URL = '/admin/acl/user/toAssign/',
  // 更新职位
  SETROLE_URL = '/admin/acl/user/doAssignRole'
}



// 获取已有用户
export const reqUserInfo = (page:number,limit:number, username:string) => request.get<any, UserResponseData>(API.ALLUSER_URL+`${page}/${limit}?username=${username}`)

// 添加修改用户
export const reqAddOrUpdateUser = (data: User) => {
  if(data.id) {
    // 更新
    return request.put<any,AddOrUpdateResponse>(API.UPDATEUSER_URL, data)
  } else {
    // 添加
    return request.post<any,AddOrUpdateResponse>(API.ADDUSER_URL, data)
  }
}


// 删除某个账号
export const reqRemoveUser =(userId:number) => request.delete<any, any>(API.DELETEUSER_URL+`${userId}`)

// 批量删除
export const reqSelectUser = (idList:number[]) => request.delete<any, any>(API.DELETEALLUSER_URL, {data:idList})

// 获取用户职位,全部职位
export const reqAllRole = (userId: number) => request.get<any, AllRoleResponseData>(API.ALLROLE_URL+`${userId}`)

// 分配职位
export const reqSetUserRole = (data: SetRoleData) => request.post<any, any>(API.SETROLE_URL,data)



